package net.sx.minemodule.mvp.activities;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.base.MyBaseFragmentActivity;
import com.kedll.library.util.MyUtils;

import net.sx.minemodule.R;
import net.sx.minemodule.databinding.MineActivityMineOrderBinding;
import net.sx.minemodule.mvp.presenters.MineOrderPresenter;
import net.sx.minemodule.mvp.views.MineOrderView;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的订单
 *
 * @author 11470
 */
@Route(path = ARouterPath.PATH_MY_ORDER)
public class MineOrderActivity extends MyBaseFragmentActivity<MineActivityMineOrderBinding, MineOrderPresenter> implements MineOrderView {

    @Autowired(name = "orderType")
    public int orderType = 0;

    @Override
    protected int getLayout() {
        return R.layout.mine_activity_mine_order;
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        ARouter.getInstance().inject(this);
        if (getIntent().getExtras() != null) {
            orderType = getIntent().getExtras().getInt("orderType");
        }
        String[] titles = getResources().getStringArray(R.array.mine_order_tab_name);
        String[] status = getResources().getStringArray(R.array.mine_order_tab_name_api_status);
        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            Fragment fragment = (Fragment) ARouter.getInstance().build(ARouterPath.PATH_MINE_ORDER).withInt("type", Integer.parseInt(status[i])).navigation();
            fragments.add(fragment);
        }

        MyUtils.bindViewPagerAndTabLayout(getSupportFragmentManager(), fragments, titles, mBinding.viewPager, mBinding.tabLayout);
        mBinding.viewPager.setOffscreenPageLimit(titles.length);
        mBinding.viewPager.setPagingEnabled(false);
        mBinding.viewPager.setCurrentItem(orderType);
    }

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        setTitle("我的订单");
        setTopRightButton("", R.mipmap.icon_msg, v -> ARouter.getInstance()
                .build(ARouterPath.PATH_MESSAGE_LIST)
                .navigation());
    }

    @Override
    protected MineOrderPresenter getPresenter() {
        return new MineOrderPresenter(this);

    }


    @Override
    public void initViewPager(List<Fragment> fragments) {

    }
}
